//
//  ViewForTravelTabViewHeader.m
//  ProjectA
//
//  Created by dllo on 16/3/11.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "ViewForTravelTabViewHeader.h"
#import "NSString+HeightLabel.h"
#import "ModelForTravelTabViewHeader.h"
#import <UIImageView+WebCache.h>
#import "AppMacro.h"
@interface ViewForTravelTabViewHeader ()

@property (nonatomic, strong) UILabel *labelForName;    //用户名
@property (nonatomic, strong) UILabel *labelForTitle;   //文章标题
@property (nonatomic, strong) UIView *viewForWhiteLine;      //白线
@property (nonatomic, strong) UILabel *labelForFirst_day;   //开始时间
@property (nonatomic, strong) UILabel *labelForDay_count;   //天数
@property (nonatomic, strong) UILabel *labelForLicheng;     //里程
@property (nonatomic, strong) UILabel *labelForMileage;     //里程公里数
@property (nonatomic, strong) UILabel *labelForXihuan;      //喜欢
@property (nonatomic, strong) UILabel *labelForRecommendations; //喜欢数
@property (nonatomic, strong) UIView *viewForGreenLine; //绿线
@property (nonatomic, strong) UIImageView *imageViewForShu; //树logo
@property (nonatomic, strong) UILabel *labelForSights;  //景点数
@property (nonatomic, strong) UIImageView *imageViewForCanyin;  //餐饮logo
@property (nonatomic, strong) UILabel *labelForRestaurant;  //餐饮数
@property (nonatomic, strong) UIImageView *imageViewForZhusu;   //楼房logo
@property (nonatomic, strong) UILabel *labelForHotel;   //住宿数
@property (nonatomic, strong) UIImageView *imageViewForGouwu;   //购物logo
@property (nonatomic, strong) UILabel *labelForMall;
@end

@implementation ViewForTravelTabViewHeader
- (void)dealloc {
    
    [_labelForMall release];
    [_imageViewForGouwu release];
    [_labelForHotel release];
    [_imageViewForZhusu release];
    [_labelForRestaurant release];
    [_imageViewForCanyin release];
    [_labelForSights release];
    [_imageViewForShu release];
    [_viewForGreenLine release];
    [_labelForRecommendations release];
    [_labelForXihuan release];
    [_labelForMileage release];
    [_labelForLicheng release];
    [_labelForDay_count release];
    [_labelForFirst_day release];
    [_viewForWhiteLine release];
    [_labelForTitle release];
    [_labelForName release];
    
    [_imageViewForAvatar_l release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageViewForAvatar_l = [[UIImageView alloc] init];
        [self addSubview:self.imageViewForAvatar_l];
        [_imageViewForAvatar_l release];
        
        self.labelForName = [[UILabel alloc] init];
        [self addSubview:self.labelForName];
        [_labelForName release];
        self.labelForName.textAlignment = 1;
        self.labelForName.font = [UIFont systemFontOfSize:13];

        self.labelForTitle = [[UILabel alloc] init];
        [self addSubview:self.labelForTitle];
        [_labelForTitle release];
        self.labelForTitle.font = [UIFont systemFontOfSize:20];
        self.labelForTitle.textAlignment = 1;
        self.labelForTitle.numberOfLines = 0;
        
        self.viewForWhiteLine = [[UIView alloc] init];
        [self addSubview:self.viewForWhiteLine];
        [_viewForWhiteLine release];
        
        self.labelForFirst_day = [[UILabel alloc] init];
        [self addSubview:self.labelForFirst_day];
        [_labelForFirst_day release];
        self.labelForFirst_day.textAlignment = 1;
        self.labelForFirst_day.font = [UIFont systemFontOfSize:10];
        
        self.labelForDay_count = [[UILabel alloc] init];
        [self addSubview:self.labelForDay_count];
        [_labelForDay_count release];
        self.labelForDay_count.textAlignment = 1;
        self.labelForDay_count.font = [UIFont systemFontOfSize:10];
        
        self.labelForLicheng = [[UILabel alloc] init];
        [self addSubview:self.labelForLicheng];
        [_labelForLicheng release];
        self.labelForLicheng.textAlignment = 1;
        self.labelForLicheng.font = [UIFont systemFontOfSize:10];
        
        self.labelForMileage = [[UILabel alloc] init];
        [self addSubview:self.labelForMileage];
        [_labelForMileage release];
        self.labelForMileage.textAlignment = 1;
        self.labelForMileage.font = [UIFont systemFontOfSize:10];
        
        self.labelForXihuan = [[UILabel alloc] init];
        [self addSubview:self.labelForXihuan];
        [_labelForXihuan release];
        self.labelForXihuan.textAlignment = 1;
        self.labelForXihuan.font = [UIFont systemFontOfSize:10];
        
        self.labelForRecommendations = [[UILabel alloc] init];
        [self addSubview:self.labelForRecommendations];
        [_labelForRecommendations release];
        self.labelForRecommendations.textAlignment = 1;
        self.labelForRecommendations.font = [UIFont systemFontOfSize:10];
        
        self.viewForGreenLine = [[UIView alloc] init];
        [self addSubview:self.viewForGreenLine];
        [_viewForGreenLine release];
        
        self.imageViewForShu = [[UIImageView alloc] init];
        [self addSubview:self.imageViewForShu];
        [_imageViewForShu release];
        
        self.labelForSights = [[UILabel alloc] init];
        [self addSubview:self.labelForSights];
        [_labelForSights release];
        self.labelForSights.textAlignment = 1;
        self.labelForSights.font = [UIFont systemFontOfSize:15];
        
        self.imageViewForCanyin = [[UIImageView alloc] init];
        [self addSubview:self.imageViewForCanyin];
        [_imageViewForCanyin release];
        
        self.labelForRestaurant = [[UILabel alloc] init];
        [self addSubview:self.labelForRestaurant];
        [_labelForRestaurant release];
        self.labelForRestaurant.textAlignment = 1;
        self.labelForRestaurant.font = [UIFont systemFontOfSize:15];
        
        self.imageViewForZhusu = [[UIImageView alloc] init];
        [self addSubview:self.imageViewForZhusu];
        [_imageViewForZhusu release];
        
        self.labelForHotel = [[UILabel alloc] init];
        [self addSubview:self.labelForHotel];
        [_labelForHotel release];
        self.labelForHotel.textAlignment = 1;
        self.labelForHotel.font = [UIFont systemFontOfSize:15];
        
        self.imageViewForGouwu = [[UIImageView alloc] init];
        [self addSubview:self.imageViewForGouwu];
        [_imageViewForGouwu release];
        
        self.labelForMall = [[UILabel alloc] init];
        [self addSubview:self.labelForMall];
        [_labelForMall release];
        self.labelForMall.textAlignment = 1;
        self.labelForMall.font = [UIFont systemFontOfSize:15];
    }
    return self;
    
}
#define WIDTH self.bounds.size.width
#define HEIGHT_AVATAR_L self.imageViewForAvatar_l.frame.size.height
#define HEIGHT_TITLE self.labelForTitle.frame.size.height
#define WIDTH_WHITE_LINE self.viewForWhiteLine.frame.size.width
#define ORIGIN_Y_GREEN_LINE self.viewForGreenLine.frame.origin.y
#define ORIGIN_X_GREEN_LINE self.viewForGreenLine.bounds.origin.x
#define WIDTH_GREEN_LINE self.viewForGreenLine.frame.size.width
- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.imageViewForAvatar_l.center = CGPointMake(WIDTH / 2.f, 0);
    self.imageViewForAvatar_l.layer.cornerRadius = self.imageViewForAvatar_l.frame.size.width / 2.f;
    self.imageViewForAvatar_l.layer.masksToBounds = YES;
    
    self.labelForName.frame = CGRectMake(20, WIDTH / 5.f / 2.f + 5, WIDTH - 40, 20);
    
    // 文章标题名, 自适应高度
    self.labelForTitle.frame = CGRectMake(40, WIDTH / 5.f / 2.f + 5 + 10 + 20, WIDTH - 80, [NSString heightForLabel:self.labelForTitle.text withWidth:WIDTH - 80 withEdge:0 withFontOfSize:20]);
    
    self.viewForWhiteLine.frame = CGRectMake(30, WIDTH / 5.f / 2.f + 5 + 10 + 20 + HEIGHT_TITLE + 15, WIDTH - 60, 1);
    
    self.labelForFirst_day.frame = CGRectMake(30, WIDTH / 5.f / 2.f + 5 + 10 + 20 + HEIGHT_TITLE + 15 + 1 + 10, WIDTH_WHITE_LINE / 3.f, 20);
    
    
    self.labelForDay_count.frame = CGRectMake(30, WIDTH / 5.f / 2.f + 5 + 10 + 20 + HEIGHT_TITLE + 15 + 1 + 10 + 20, WIDTH_WHITE_LINE / 3.f, 20);
    
    
    self.labelForLicheng.frame = CGRectMake(30 + WIDTH_WHITE_LINE / 3.f, WIDTH / 5.f / 2.f + 5 + 10 + 20 + HEIGHT_TITLE + 15 + 1 + 10, WIDTH_WHITE_LINE / 3.f, 20);
    
    
    self.labelForMileage.frame = CGRectMake(30 + WIDTH_WHITE_LINE / 3.f, WIDTH / 5.f / 2.f + 5 + 10 + 20 + HEIGHT_TITLE + 15 + 1 + 10 + 20, WIDTH_WHITE_LINE / 3.f, 20);
    
    
    self.labelForXihuan.frame = CGRectMake(30 + WIDTH_WHITE_LINE / 3.f * 2, WIDTH / 5.f / 2.f + 5 + 10 + 20 + HEIGHT_TITLE + 15 + 1 + 10, WIDTH_WHITE_LINE / 3.f, 20);
    
    
    self.labelForRecommendations.frame = CGRectMake(30 + WIDTH_WHITE_LINE / 3.f * 2, WIDTH / 5.f / 2.f + 5 + 10 + 20 + HEIGHT_TITLE + 15 + 1 + 10 + 20, WIDTH_WHITE_LINE / 3.f, 20);
    
    
    self.viewForGreenLine.frame = CGRectMake(15, WIDTH / 5.f / 2.f + 5 + 10 + 20 + HEIGHT_TITLE + 15 + 1 + 10 + 20 + 20 + 20, WIDTH - 30, 3);
    
    self.imageViewForShu.frame = CGRectMake(30, ORIGIN_Y_GREEN_LINE + 15, WIDTH / 12.f, WIDTH / 12.f);

    self.labelForSights.frame = CGRectMake(30 + WIDTH / 12.f + 5, ORIGIN_Y_GREEN_LINE + 15, WIDTH / 12.f * 2, WIDTH / 12.f);
    
    
    self.imageViewForCanyin.frame = CGRectMake(ORIGIN_X_GREEN_LINE + WIDTH_GREEN_LINE / 2.f + 20, ORIGIN_Y_GREEN_LINE + 15, WIDTH / 12.f, WIDTH / 12.f);
    
    self.labelForRestaurant.frame = CGRectMake(self.imageViewForCanyin.frame.origin.x + self.imageViewForCanyin.frame.size.width + 5 + 20, ORIGIN_Y_GREEN_LINE + 15, WIDTH / 12.f * 2, WIDTH / 12.f);
    
    self.imageViewForZhusu.frame = CGRectMake(30, ORIGIN_Y_GREEN_LINE + 15 + WIDTH / 12.f + 5, WIDTH / 12.f, WIDTH / 12.f);
    self.labelForHotel.frame = CGRectMake(30 + WIDTH / 12.f + 5, ORIGIN_Y_GREEN_LINE + 15 + WIDTH / 12.f + 5, WIDTH / 12.f * 2, WIDTH / 12.f);
    
    self.imageViewForGouwu.frame = CGRectMake(ORIGIN_X_GREEN_LINE + WIDTH_GREEN_LINE / 2.f + 20, ORIGIN_Y_GREEN_LINE + 15 + WIDTH / 12.f + 5, WIDTH / 12.f, WIDTH / 12.f);
    
    self.labelForMall.frame = CGRectMake(self.imageViewForCanyin.frame.origin.x + self.imageViewForCanyin.frame.size.width + 5 + 20, ORIGIN_Y_GREEN_LINE + 15 + WIDTH / 12.f + 5, WIDTH / 12.f * 2, WIDTH / 12.f);
    
    [UIView setColorWithLabelText:self.labelForName nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForTitle nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithView:self.viewForWhiteLine nightColor:RGBA(205, 205, 205, 1) dayColor:L_COLOR_GRAY];
    [UIView setColorWithLabelText:self.labelForFirst_day nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForDay_count nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForLicheng nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForMileage nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForXihuan nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForRecommendations nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithView:self.viewForGreenLine nightColor:L_COLOR_LIGHTGRAY dayColor:RGBA(49, 211, 209, 1)];
    [UIView setColorWithLabelText:self.labelForSights nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForRestaurant nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForHotel nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    [UIView setColorWithLabelText:self.labelForMall nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
}
- (void)passData:(ModelForTravelTabViewHeader *)model {
    
    
    // 用户头像初始化大小, (为了动画效果, 所以写在此处)
    self.imageViewForAvatar_l.frame = CGRectMake(0, -(WIDTH / 5.f) / 2.f, WIDTH / 5.f, WIDTH / 5.f);
    
    [self.imageViewForAvatar_l sd_setImageWithURL:[NSURL URLWithString:[model.user objectForKey:@"avatar_l"]] placeholderImage:[UIImage imageNamed:@"iconfont-nansheng"]];
    
    self.labelForTitle.text = model.name;
    
    self.labelForName.text = [model.user objectForKey:@"name"];

    self.labelForFirst_day.text = model.first_day;

    NSString *count = [NSString stringWithFormat:@"%@天", model.day_count];
    self.labelForDay_count.text = count;
    
    self.labelForLicheng.text = @"里程";
    NSString *mileage = [NSString stringWithFormat:@"%@", model.mileage];
    mileage = [mileage substringToIndex:[mileage rangeOfString:@"."].location];
    mileage = [mileage stringByAppendingString:@"km"];
    self.labelForMileage.text = mileage;
    
    self.labelForXihuan.text = @"喜欢";
    self.labelForRecommendations.text = [model.recommendations stringValue];
    
    self.imageViewForShu.image = [UIImage imageNamed:@"iconfont-shu"];
    NSString *sights = [NSString stringWithFormat:@"%@ 景点", [model.poi_infos_count objectForKey:@"sights"]];
    self.labelForSights.text = sights;
    
    self.imageViewForCanyin.image = [UIImage imageNamed:@"iconfont-canyin"];
    NSString *restaurant = [NSString stringWithFormat:@"%@ 餐饮", [model.poi_infos_count objectForKey:@"restaurant"]];
    self.labelForRestaurant.text = restaurant;
    
    self.imageViewForZhusu.image = [UIImage imageNamed:@"iconfont-zhusu"];
    NSString *hotel = [NSString stringWithFormat:@"%@ 住宿", [model.poi_infos_count objectForKey:@"hotel"]];
    self.labelForHotel.text = hotel;
    
    self.imageViewForGouwu.image = [UIImage imageNamed:@"iconfont-gouwu"];
    NSString *mall = [NSString stringWithFormat:@"%@ 购物", [model.poi_infos_count objectForKey:@"mall"]];
    self.labelForMall.text = mall;
    
}
@end
